package com.android.camera.ui;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.DashPathEffect;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PathEffect;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import com.android.camera.R;

public class TwoLineView extends View {
    private Paint mPaint;
    // private Paint mBackgroundPaint;

    private float line1Y = 0, line2Y = 0;

    private int width = 0;
    private int height = 0;

    private int padding = 30;
    private int halfLineGap = 96;

    public TwoLineView(Context context) {
        super(context, null);
    }

    public TwoLineView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public TwoLineView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        mPaint = new Paint();
        mPaint.setAntiAlias(true);
        mPaint.setColor(getResources().getColor(R.color.camera_highlight));
        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setStrokeWidth(3);
        PathEffect effect = new DashPathEffect(new float[] {
                15, 10, 15, 10
        }, 1);
        mPaint.setPathEffect(effect);

        /*
         * mBackgroundPaint = new Paint(); mBackgroundPaint.setAntiAlias(true);
         * mBackgroundPaint.setStyle(Paint.Style.FILL);
         * mBackgroundPaint.setColor(0x20000000);
         */
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        Log.d("sqm", "TwoLineView left=" + getLeft() + ", right=" + getRight() + ", top="
                + getTop() + ", bottom=" + getBottom());

        // RectF r = new RectF(30, startY - 96, width - 30, startY + 96);
        // canvas.drawRect(r, mBackgroundPaint);

        line1Y = height / 2.0f - halfLineGap;
        line2Y = height / 2.0f + halfLineGap;
        Path p1 = new Path();
        p1.moveTo(padding, line1Y);
        p1.lineTo(width - padding, line1Y);
        canvas.drawPath(p1, mPaint);
        Path p2 = new Path();
        p2.moveTo(padding, line2Y);
        p2.lineTo(width - padding, line2Y);
        canvas.drawPath(p2, mPaint);
    }

    @Override
    protected void onLayout(boolean changed, int left, int top, int right,
            int bottom) {
        super.onLayout(changed, left, top, right, bottom);
        width = right - left;
        height = bottom - top;

    }

}
